package treeHoleSERVICE;

import com.sun.org.apache.bcel.internal.classfile.InnerClass;
import com.sun.org.apache.bcel.internal.classfile.InnerClasses;
import treeHoleDAO.PersonalInformation;
import treeHoleDAO.PersonalInformationIMPH;
import treeHoleDAO.PublicTreeHoleIMPH;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @program:IntelliJ IDEA
 * @Description:PostMessage的实现类
 * @author:Mr.CheCheHuiBujianO
 * @data: 2022/6/19 17:16
 */
public class PostMessageIMPH implements PostMessage{
    /**
     * @param userAccount
     * @Description: 根据人的账号找到相应的用户的历史发布
     * @Param: [userName]
     * @return:java.util.List<treeHoleSERVICE.User.userHistory>
     * @Author: Mr.yue
     * @Date: 2022/6/16 22:22
     */
    @Override
    public List<User.UserHistory> historyPostMessage(int userAccount) {
        //从DAO取用数据
        new PersonalInformationIMPH().PersonalInformationFile(userAccount);
        User user = new PersonalInformationIMPH().readUserHistoryEssayAndShowUI(userAccount);
        return user.userEssayCollection;
    }

    /**
     * @param userName
     * @param title
     * @Description: 点赞数量加一
     * @Param: [userName, title]
     * @return:[java.lang.String, java.lang.String]
     * @Author: Mr.yue
     * @Date: 2022/6/16 18:20
     */
    @Override
    public boolean giveLike(String userName, String title) {
        return false;
    }

    /**
     * @param user
     * @Description: 根据用户账号将发帖内容存入我们相应的用户文本文件并需要加将其添加到我们公共树洞
     *               要写入到公共树洞和个人文件
     *
     * @Param: [user]
     * @return:void
     * @Author: Mr.yue
     * @Date: 2022/6/16 22:40
     */
    @Override
    public User postMessage(User user) {
        Date nowDate = new Date();

        //利用getText得到文章的标题和内容
        int userAccount = user.userEssayCollection.get(0).userAccount;
        String title = user.userEssayCollection.get(0).title;
        String essayContent = user.userEssayCollection.get(0).essayContent;
        new PersonalInformationIMPH().WritePersonalInformationFile(userAccount,nowDate,title,essayContent);
        new PublicTreeHoleIMPH().writeTreeHoleFile(user.userEssayCollection);
        return user;
    }
}
